package edu.ciee.tz.dao;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Component;

import edu.ciee.tz.model.ZaiqianEb;

@Component("zaiqianebDao")
public class ZaiqianEbDAO {

	public List<ZaiqianEb> search(ZaiqianEb z) throws Exception {

		String query = "where 1=1";

		if (z.getId() != 0) 
			query = query + " and id like '%" + z.getId() + "%'";// this.getID()
		if (z.getEb_id() != null) 
			query = query + " and eb_id like '%" + z.getEb_id() + "%'"; // this.getName()
		if (z.getZaiqian_id()!=null&&z.getZaiqian_id().getId()!= 0) 
			query = query + " and zaiqian_id like '%" + z.getZaiqian_id().getId()+ "%'";// this.getID()
		if (z.getResult() != null) 
			query = query + " and result like '%" + z.getResult()+ "%'";// this.getID()
		if (z.getDeal() != null) 
			query = query + " and deal like '%" + z.getDeal()+ "%'";// this.getID()
		
		@SuppressWarnings("unchecked")
		List<ZaiqianEb> zaiqian_list = hibernateTemplate.find("from ZaiqianEb u "+ query);

		return zaiqian_list;
	}

	public void insert(ZaiqianEb z) throws Exception {
		this.getHibernateTemplate().save(z);
	}

	public void delete(ZaiqianEb z) throws Exception {
		this.getHibernateTemplate().delete(z);

	}

	public void update(ZaiqianEb z) throws Exception {
		this.getHibernateTemplate().update(z);
	}

	private HibernateTemplate hibernateTemplate;

	public HibernateTemplate getHibernateTemplate() {
		return hibernateTemplate;
	}

	@Resource
	public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
		this.hibernateTemplate = hibernateTemplate;
	}
}
